package practice;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class _04CatchChikens {
    static int res = 0;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int stuNum = scanner.nextInt();
        //int[] a = new int[stuNum], b = new int[stuNum];
        Queue<Integer> queueA = new LinkedList<>(); //  harms
        Queue<Integer> queueB = new LinkedList<>(); //  students
        for (int i = 0;i < stuNum;i++){
            queueB.add(scanner.nextInt());
        }
        for (int i = 0;i < stuNum;i++){
            queueA.add(scanner.nextInt());
        }
        //adjust(queueA,queueB);
        //attack(queueA,queueB);
        backTrack(queueA,queueB);
        System.out.println(res);
    }

    private static int backTrack(Queue<Integer> queueA, Queue<Integer> queueB) {
        //  学生每次都有两种选择，一种是调整，另一种是攻击
        //  难点是如何实现做出选择
        for (int i = 0;i < queueB.size();i++){

        }
        return res;
    }

    private static void adjust(Queue<Integer> queueA, Queue<Integer> queueB) {
        //  调整
        int elem = queueA.remove();
        queueA.add(elem);
        elem = queueB.remove();
        queueB.add(elem);
    }

    private static boolean attack(Queue<Integer> queueA, Queue<Integer> queueB) {
        //  攻击
        if (queueA.isEmpty()){
            return false;
        }
        int harm = queueA.peek();
        int bLens = queueB.size();
        if (harm > bLens){
            return false;
        }
        //  造成伤害的同时，学生离队
        res += harm;
        while (harm-- > 0){
            queueB.remove();
            //  学生离队后，A需要除去非必要数据
            queueA.remove();
        }
        return true;
    }
}
